package com.sinothk.gpserver.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.sinothk.gpserver.util.DateUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 编写 Liang Y.T.
 * 时间 2021/8/28 13:00
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.hasGetter("createTime")) {
            this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, DateUtils.getLocalDateTime()); // 起始版本 3.3.0(推荐使用)
        }
        if (metaObject.hasGetter("updateTime")) {
            this.strictInsertFill(metaObject, "publishDate", LocalDateTime.class, DateUtils.getLocalDateTime()); // 起始版本 3.3.0(推荐使用)
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasSetter("updateTime")) {
            this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, DateUtils.getLocalDateTime()); // 起始版本 3.3.0(推荐使用)​
        }
    }

}
